/*INIT*/
$(document).ready(function() {
	$.ajax({
        url : getRootPath() + '/customerajax/presentConsume!queryGiftHistory.action',
        cache : false, 
        async : true,
        type : "POST",
        dataType : 'json',
        beforeSend	: function(xmlHttpRequest){
			//开启提交动画
		},
        success : function (result){
		    //关闭提交动画，响应成功请求        	
        	loadAllPresentConsume(result);        
        	giftList.init();
        },
        error	:	function(){
        	//关闭提交动画，响应失败请求
        	alert("error");
        }
    });
});

var giftList = {
	init: function() {
		$('.listItem > a').click(giftList.toggle);
		$('.detailArea .fold').click(giftList.toggle);
	},
	toggle: function() {
		var detailArea = $(this).parentsUntil('ul').find('.detailArea');
		if(detailArea.css('display') == 'none') detailArea.show();
		else detailArea.hide();
		if($.browser.msie && $.browser.version < 8) $('.listArea li').css('zoom', '0').css('zoom', '1');
	}
};
function loadAllPresentConsume(data) {
	//set customer information
	var tips = '欢迎您，亲爱的'+data.customerName+',最近一个月你在飞饭完成了 <em>'+data.monthOrdersCount+'</em> 个订单，吃过 <em>'+data.monthProductCount+'</em> 份美食，已经有了 <em>'+data.creditPoint+'</em> 点积分。 去<a href="'+getRootPath()+'/presentCenter">礼品中心</a>看看。';
	$('.tips .body').html(tips);
	//set customer's presentConsume information
	var item = null;
	$.each(data.pOrderSequences, function(i){
		item = '<li><div class=\"listItem li_1\"><a href=\"javascript:void(0);\">'+data.pOrderSequences[i]+
		 '</a></div><div class=\"listItem li_2\"><a href=\"javascript:void(0);\">'+data.pnames[i]+
		 '</a></div><div class=\"listItem li_3\">'+data.amounts[i]+
		 '</div><div class=\"listItem li_4\">'+data.points[i]+
		 '</div><div class=\"listItem li_5\">'+data.createTimes[i].substr(0,10)+
		 '</div><div class=\"listItem li_6\">'+data.contactNames[i]+
		 '</div><div class=\"listItem li_7\"><a href=\"javascript:void(0);\">查看物流</a></div><div class=\"clear\"></div><div class=\"detailArea\"><div class=\"detailItem di_1\"><b>手机：</b>'+data.mobiles[i]+
		 '</div><div class=\"detailItem di_2\"><b>地址：</b>'+data.addresss[i]+
		 '</div><div class=\"detailItem di_3\"><b>物流状态：</b>'+data.deliveryStatuss[i]+
		 '</div><div class=\"clear\"></div><div class=\"fold\">收起<div class=\"icon\"></div></div></div></li>';
		$('.listArea .body').append(item);
	});
	
}